import { Component, OnInit } from '@angular/core';
import * as constants from '../../../providers/Constants'
import { NavController, AlertController } from '@ionic/angular';
import { ToastService } from './../../../providers/toast/toast.service'
import { Storage } from 'src/app/providers/Storage';
import { AuthService } from 'src/app/services/auth.service';
import { Utils } from 'src/app/providers/Utils';
@Component({
  selector: 'app-friends-share',
  templateUrl: './friends-share.page.html',
  styleUrls: ['./friends-share.page.scss'],
})
export class FriendsSharePage implements OnInit {
  value:string=''
  constructor(private toast: ToastService,
    private alertController: AlertController,
    public nav: NavController,
    public service: AuthService, ) {

  }

  ngOnInit() {
    this.service.getShareApp({}).subscribe(res => {
      // 保存成功返沪上一页，否则弹出提示框
      if (res.retCode == '000000') {
        console.log('分享的好友');
          this.value=res.userCode
        // this.getUserInfo();
      } else if (constants.errCode[res.retCode]) {
        if (constants.errCode[res.retCode] != '0') {
          this.toast.show(constants.errCode[res.retCode]);
        }
      } else if (res.retMsg) {
        this.toast.show(res.retMsg);
      } else {
        this.toast.show("exception service routine");
      }
    });
  }
  btn(){
    this.copyToClipboard(this.value);
  }
  copyToClipboard(value) {
    var aux = document.createElement("input");
    var _content = value ;
    aux.setAttribute("value", _content);
    document.body.appendChild(aux);
    aux.select();
    document.execCommand("Copy");
    document.body.removeChild(aux);
    this.toast.show('Copy success')
}
}
